﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common
{
    public static class Configuration
    {
        #region Consts
        private const String REG_KEY = @"Software\Presbeton";
        #endregion Consts

        #region Members
        private static RegistryKey m_regKeyRoot;
        #endregion Members

        #region Constructor
        static Configuration()
        {
            try
            {
                m_regKeyRoot = Registry.LocalMachine.OpenSubKey(REG_KEY);
            }
            catch (Exception ex)
            {
                EventLogManager.LogError(ex);
            }
            try
            {
                Debug = false;
                Debug = m_regKeyRoot != null
                    ? (int)m_regKeyRoot.GetValue("Debug") == 1
                    : false;

                if (Debug)
                    EventLogManager.LogError(new Exception("Debug mode is active."));
            }
            catch
            {
                //EventLogManager.LogError(ex);
            }
        }
        #endregion Constructor

        public static bool Debug { set; get; }

        public static String DBServer
        {
            get
            {
                return m_regKeyRoot != null
                    ? (String)m_regKeyRoot.GetValue("DBServer")
                    : String.Empty;
            }
        }

        public static String DBName
        {
            get
            {
                return m_regKeyRoot != null
                    ? (String)m_regKeyRoot.GetValue("DBName")
                    : String.Empty;
            }
        }

        public static int ReceivePort
        {
            get
            {
                return m_regKeyRoot != null
                    ? (int)m_regKeyRoot.GetValue("ReceivePort")
                    : 2000;
            }
        }
    }
}
